package com.cmhi.softmbh.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.cmhi.softmbh.cache.StaticConst;
import com.softmbh.kellyplatform.util.AppUtils;

public class DatabaseHelper extends SQLiteOpenHelper {
    private String TAG = "baimeng";
    private static final String DATABASE_NAME = "authentication.db";
    private static final int DATABASE_VERSION = 1;
    public static final String SHARE_INFO_TABLE_NAME = "shareInfo";

    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        AppUtils.Log(TAG, "DatabaseHelper.onCreate");
        if (StaticConst.platformType == StaticConst.platformTypeZTE) {
            try {
                AppUtils.Log(TAG, "DatabaseHelper.onCreate.zhongxing");
                // 创建ZhongXing表
                db.execSQL("CREATE TABLE " + Provider.ZhongXingColumns.TABLE_NAME + " ("
//                    + Provider.ZhongXingColumns._ID + " INTEGER PRIMARY KEY,"
                        + Provider.ZhongXingColumns.NAME + " TEXT,"
                        + Provider.ZhongXingColumns.VALUE + " TEXT"
                        + ");");
            } catch (Exception e) {
                AppUtils.Log(TAG, "DatabaseHelper.failure");
                e.printStackTrace();
            }
        } else if (StaticConst.platformType == StaticConst.platformTypeHUAWEI) {
            try {
                AppUtils.Log(TAG, "DatabaseHelper.onCreate.huawei");
                // 创建HuaWei表
                db.execSQL("CREATE TABLE " + Provider.HuaWeiColumns.TABLE_NAME + " ("
//                    + Provider.HuaWeiColumns._ID + " INTEGER PRIMARY KEY,"
                        + Provider.HuaWeiColumns.NAME + " TEXT,"
                        + Provider.HuaWeiColumns.VALUE + " TEXT"
                        + ");");
            } catch (Exception e) {
                AppUtils.Log(TAG, "DatabaseHelper.failure");
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        AppUtils.Log(TAG, "DatabaseHelper.onUpgrade");
        db.execSQL("DROP TABLE IF EXISTS " + Provider.ZhongXingColumns.TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + Provider.HuaWeiColumns.TABLE_NAME);
        onCreate(db);
    }
}